
---@class RedDotsBillboardHandler
RedDotsBillboardHandler ={};
local this = RedDotsBillboardHandler;

function RedDotsBillboardHandler.init()

    CloseEvent(Config.EventType.BillboardUpdate,this.update);
    ListenEvent(Config.EventType.BillboardUpdate,this.update);
    CloseEvent(Config.EventType.RefreshNoticeBless,this.update);
    ListenEvent(Config.EventType.RefreshNoticeBless,this.update);
    --CloseEvent(Config.EventType.RefreshNoticeSelfRank,this.update);
    --ListenEvent(Config.EventType.RefreshNoticeSelfRank,this.update);
    CloseEvent(Config.EventType.BillboardRewardRedPoint,this.update);
    ListenEvent(Config.EventType.BillboardRewardRedPoint,this.update);

    CloseEvent(Config.EventType.Billboard_rank_reddot_refresh,this.update);
    ListenEvent(Config.EventType.Billboard_rank_reddot_refresh,this.update);

    --CloseEvent(Config.EventType.RefreshNoticeGetRankReward,this.update);
    --ListenEvent(Config.EventType.RefreshNoticeGetRankReward,this.update);
    return this;
end

--
function RedDotsBillboardHandler.getFlag(...)
    if not logicMgr.FuncOpenManager.isOpen(Config.FuncOpenType.OperationNotice,false) then
        return Config.RedDotsFlagState.None
    end

    local mgr = logicMgr.NoticeManager
    local state = Config.RedDotsFlagState.None
    local isActive = mgr.IsOpen() and not mgr.IsTimeEnd()
    local id = ...
    --[[if id == mgr.PartBigType.power or id == mgr.PartBigType.social or id == mgr.PartBigType.cost then
        if isActive and mgr.HasRewardRedPoint(id) then
            state = Config.RedDotsFlagState.Needful
        end
    else]]
    if id == mgr.PartBigType.billboard then
        if not mgr.IsBlessed() or (isActive and mgr.HasRewardRedPointAll()) then
            state = Config.RedDotsFlagState.Needful
        end

        if mgr.IsOpen() then
            if logicMgr.BillboardMgr.NeedShowRedDot(EnumConst.BillRankType.Stage) 
            or logicMgr.BillboardMgr.NeedShowRedDot(EnumConst.BillRankType.YongJie) 
            or logicMgr.BillboardMgr.NeedShowRedDot(EnumConst.BillRankType.MagicTravel) 
            or logicMgr.BillboardMgr.NeedShowRedDot(EnumConst.BillRankType.Relic) then
                state = Config.RedDotsFlagState.Needful
            end
        end
    else
        if (isActive and mgr.HasRewardRedPointAll()) --[[or not mgr.IsBlessed()]] then
            state = Config.RedDotsFlagState.Needful
        end

        if mgr.IsOpen() then
            if logicMgr.BillboardMgr.NeedShowRedDot(EnumConst.BillRankType.Stage) 
            or logicMgr.BillboardMgr.NeedShowRedDot(EnumConst.BillRankType.YongJie) 
            or logicMgr.BillboardMgr.NeedShowRedDot(EnumConst.BillRankType.MagicTravel) 
            or logicMgr.BillboardMgr.NeedShowRedDot(EnumConst.BillRankType.Relic) then
                state = Config.RedDotsFlagState.Needful
            end
        end
    end
    return state
end


function RedDotsBillboardHandler.update()
    RedDotsManager.addBroadcast(Config.RedDotsType.Billboard);
end